#pragma once

#include <AP_HAL/AP_HAL_Boards.h>

// used by LittleFS
#define AP_FILESYSTEM_FLASH_JEDEC_NOR 1
#define AP_FILESYSTEM_FLASH_W25NXX 2

// backends:

#ifndef AP_FILESYSTEM_ESP32_ENABLED
#define AP_FILESYSTEM_ESP32_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_ESP32)
#endif

#ifndef AP_FILESYSTEM_FATFS_ENABLED
#define AP_FILESYSTEM_FATFS_ENABLED HAL_OS_FATFS_IO
#endif

#ifndef AP_FILESYSTEM_LITTLEFS_ENABLED
#define AP_FILESYSTEM_LITTLEFS_ENABLED HAL_OS_LITTLEFS_IO
#endif

#ifndef AP_FILESYSTEM_LITTLEFS_FLASH_TYPE
#define AP_FILESYSTEM_LITTLEFS_FLASH_TYPE AP_FILESYSTEM_FLASH_JEDEC_NOR
#endif

#ifndef AP_FILESYSTEM_PARAM_ENABLED
#define AP_FILESYSTEM_PARAM_ENABLED 1
#endif

#ifndef AP_FILESYSTEM_POSIX_ENABLED
#define AP_FILESYSTEM_POSIX_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL || CONFIG_HAL_BOARD == HAL_BOARD_LINUX || CONFIG_HAL_BOARD == HAL_BOARD_QURT)
#endif

#ifndef AP_FILESYSTEM_ROMFS_ENABLED
#define AP_FILESYSTEM_ROMFS_ENABLED defined(HAL_HAVE_AP_ROMFS_EMBEDDED_H)
#endif

#ifndef AP_FILESYSTEM_SYS_ENABLED
#define AP_FILESYSTEM_SYS_ENABLED 1
#endif

#ifndef AP_FILESYSTEM_POSIX_MAP_FILENAME_ALLOC
// this requires AP_FILESYSTEM_POSIX_MAP_FILENAME_BASEDIR
#define AP_FILESYSTEM_POSIX_MAP_FILENAME_ALLOC 0
#endif

// AP_FILESYSTEM_FILE_WRITING_ENABLED is true if you could expect to
// be able to open and write a non-virtual file.  Notably this
// excludes virtual files like SYSFS, and the magic param/mission
// upload targets, and also excludes ROMFS (where you can read but not
// write!)
#ifndef AP_FILESYSTEM_FILE_WRITING_ENABLED
#define AP_FILESYSTEM_FILE_WRITING_ENABLED (AP_FILESYSTEM_ESP32_ENABLED || AP_FILESYSTEM_FATFS_ENABLED || AP_FILESYSTEM_LITTLEFS_ENABLED || AP_FILESYSTEM_POSIX_ENABLED)
#endif

// AP_FILESYSTEM_FILE_READING_ENABLED is true if you could expect to
// be able to open and read a non-virtual file.  Notably this excludes
// virtual files like SYSFS, and the magic param/mission upload targets.
#ifndef AP_FILESYSTEM_FILE_READING_ENABLED
#define AP_FILESYSTEM_FILE_READING_ENABLED (AP_FILESYSTEM_FILE_WRITING_ENABLED || AP_FILESYSTEM_ROMFS_ENABLED || AP_FILESYSTEM_SYS_ENABLED || AP_FILESYSTEM_PARAM_ENABLED)
#endif

#ifndef AP_FILESYSTEM_SYS_FLASH_ENABLED
#define AP_FILESYSTEM_SYS_FLASH_ENABLED CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
#endif

#ifndef AP_FILESYSTEM_HAVE_DIRENT_DTYPE
#define AP_FILESYSTEM_HAVE_DIRENT_DTYPE 1
#endif

#ifndef AP_FILESYSTEM_MISSION_ENABLED
#include <AP_Mission/AP_Mission_config.h>
#define AP_FILESYSTEM_MISSION_ENABLED AP_MISSION_ENABLED
#endif

#ifndef AP_FATFS_MAX_IO_SIZE
#define AP_FATFS_MAX_IO_SIZE 4096
#endif

#ifndef AP_FATFS_MIN_IO_SIZE
#define AP_FATFS_MIN_IO_SIZE 4096
#endif
